import React from 'react';
import { observer, inject } from 'mobx-react';

export default class SpecialElement extends React.Component{
    componentDidMount(){
        const { fieldAttr } = this.props;
        const { detailtype,specialattr } = fieldAttr;
        //特殊字段--链接含JS情况下通过Append方式渲染
        if(detailtype === 1){
            const displayname = specialattr.displayname || "";
            const linkaddress = specialattr.linkaddress || "";
            window.jQuery(this.refs.specialFieldSpan).append("<a href='javascript:void(0)' onclick='showHoverWindow(\""+linkaddress+"\")' target='_blank'>"+displayname+"</a>");
        }
    }
    render() {
        const { fieldAttr } = this.props;
        const { detailtype,specialattr } = fieldAttr;
        let specialFieldDom;
        if(detailtype === 1){
            // const displayname = fieldObj&&fieldObj.get("specialattr") ? fieldObj.getIn(["specialattr","displayname"]) : "";
            // const linkaddress = fieldObj&&fieldObj.get("specialattr") ? fieldObj.getIn(["specialattr","linkaddress"]) : "";
            // specialFieldDom = <a href={linkaddress} target="_blank" dangerouslySetInnerHTML={{__html: displayname}}></a>
        }else if(detailtype === 0 || detailtype === 2){   //老表单有type为0的描述性文字
            const descriptivetext = specialattr.descriptivetext || "";
            specialFieldDom = <span dangerouslySetInnerHTML={{__html:descriptivetext}}></span>;
        }
        return <span className="specialField" ref="specialFieldSpan">{specialFieldDom}</span>;
    }
}